//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Example #11—Class Example
// CS 151, 6 Apr 2009
// ECC, Spring 2009
// Niko Culevski
// Program to usage of a Point class
// Note that the Class Point should be saved in a
// separate file
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class Point	// Objects represent points in the Cartesian plane
{
	// the point’s coordinates are hidden from outside
	private double x, y;
  	public Point(double a, double b)    //constructor, invoked to initialize
	{
	   x = a;
       y = b;
  	}

  public double xcoord()		//method to return x-coordinate
  {
      return x;
  }

  public double ycoord()		//method to return y-coordinate
  {
      return y;
  }

  public boolean equals(Point p)
  {
      return (x == p.x && y == p.y);
  }

  public String toString()
  {
      return new String("(" + x + ", "  + y + ")");
  }

  public static void main(String args[])

    /*The line that follows does three things:
    1.	it declares p to be a reference to Point objects.
    2.	it applies the new operator to create a point object with values
    2 and 3 for the fields x and y.
    3.	it initializes the reference p with this new objects.
    */
  {
      Point p = new Point(2,3);     // instantiate a point object

      System.out.println("p.xcoord() = " + p.xcoord() + ", p.ycoord() = "
            + p.ycoord ());

      // display the point p using its toString() method
      System.out.println("p = " + p);

      // create anoher point
      Point q = new Point(7,4);
      System.out.println("q = " + q);

      // check if p and q are equal using the equals() method
      if (q.equals(p))
          System.out.println("q equals p");
      else
          System.out.println("q does not equal p");

      q = new Point(2,3);
      System.out.println("q = " + q);
      if (q.equals(p))
          System.out.println("q equals p");
      else
          System.out.println("q does not equal p");
  }
}